package com.minhua.jijiehao2.mainframe.launcher.registeractivity.impl

import android.text.TextUtils
import com.minhua.jijiehao2.base.BaseMvpPresenter
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.bean.CheckCodeBean
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.constants.HttpConst
import com.minhua.jijiehao2.http.CallBack
import com.minhua.jijiehao2.http.ParamsMap
import com.minhua.jijiehao2.mainframe.launcher.registeractivity.imp.IRegisterPresenter
import com.minhua.jijiehao2.mainframe.launcher.registeractivity.imp.IRegisterView
import com.minhua.jijiehao2.utils.T

internal class RegisterPresenter : BaseMvpPresenter<IRegisterView>(), IRegisterPresenter {

    private var mRegisterModel = RegisterModel()

    override fun sendCode() {
        val userName = v?.getUserName() ?: ""
        if (TextUtils.isEmpty(userName) || userName.length != 11) {
            v?.onUserNameError()
            return
        }
        val map = ParamsMap()
        map.put(DefineKey.PHONE, userName)
        map.put(DefineKey.CHECK_TYPE, DefineKey.REGISTER_CODE)
        mRegisterModel.sendCode(map, object : CallBack<CheckCodeBean>() {
            override fun onSuccess(t: BaseBean<CheckCodeBean>) {
                val data = t.data
                if (data?.state ?: "" == HttpConst.STATE_10) {
                    v?.onSendCodeSuccess(t.msg!!)
                } else {
                    T.showShort(data?.message)
                }
            }
        })
    }
}